//
//  LBRightCell.m
//  loveBeen
//
//  Created by guofei on 2016/11/19.
//  Copyright © 2016年 loveBeen. All rights reserved.
//

#import "LBRightCell.h"
#import "LBSuperMarketProducts.h"



@interface LBRightCell ()

//图片
@property (weak, nonatomic) IBOutlet UIImageView *img;

/*名字*/
@property (weak, nonatomic) IBOutlet UILabel *name;

/*is精选*/
@property (weak, nonatomic) IBOutlet UIImageView *jxImg;

/*买一赠一*/
@property (weak, nonatomic) IBOutlet UIImageView *buyOneImg;

/*详情*/
@property (weak, nonatomic) IBOutlet UILabel *specificsLabel;

/*现价*/
@property (weak, nonatomic) IBOutlet UILabel *partnerPriceLabel;

/*原价*/
@property (weak, nonatomic) IBOutlet UILabel *marketPriceLabel;

// 购买数量
@property (weak, nonatomic) IBOutlet UILabel *buyNumLabel;

// 减号按钮
@property (weak, nonatomic) UIButton *minusBtn;


// 补货中
@property (weak, nonatomic) IBOutlet UILabel *captureLabel;


//约束
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *nameLabelLeadingConstraint;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *jxImgWidthConstraint;




@end

@implementation LBRightCell

- (void)setModel:(LBSuperMarketProducts *)model{
    _model = model;
    
    _model.isAnimation = YES;
    
    _plusMinusView.model = _model;
    
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.img]];
    
    self.name.text = model.name;
    if (model.is_xf.intValue == 1) {
        self.jxImgWidthConstraint.constant = 30;
        self.nameLabelLeadingConstraint.constant = 38;
        self.jxImg.image = [UIImage imageNamed:@"jingxuan.png"];
    }else{
        self.jxImgWidthConstraint.constant = 0;
        self.nameLabelLeadingConstraint.constant = 0;
    }
    if (model.pm_desc.length <= 0) {
        self.buyOneImg.hidden = YES;
    }else{
        self.buyOneImg.hidden = NO;
    }
    self.specificsLabel.text = model.specifics;
    self.partnerPriceLabel.text = [NSString stringWithFormat:@"￥%@",model.partner_price];
    if ([model.market_price isEqualToString:model.partner_price]) {
        self.marketPriceLabel.text = @"";
    }else{
        self.marketPriceLabel.text = [NSString stringWithFormat:@"￥%@",model.market_price];
    }
    
    if (model.store_nums.intValue <= 1) {
        self.captureLabel.hidden = NO;
        self.plusMinusView.hidden = YES;
    }else{
        self.captureLabel.hidden = YES;
        self.plusMinusView.hidden = NO;
    }
    
//    self.marketPrice_Label.constant = 10 * self.marketPriceLabel.text.length;
    
    NSMutableAttributedString *newPrice = [[NSMutableAttributedString alloc] initWithString:_marketPriceLabel.text];
    [newPrice addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, newPrice.length)];
    self.marketPriceLabel.attributedText = newPrice;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];

    [self plusAndMinusView];

}

- (void)plusAndMinusView{

    // MARK: - 加减号 view
    LBMinusPlusView *plusMinusView = [[[UINib nibWithNibName:@"LBMinusPlusView" bundle:nil] instantiateWithOwner:nil options:nil] lastObject];
    [self.contentView addSubview:plusMinusView];
    
    [plusMinusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.bottom.offset(-7);
        make.size.mas_equalTo(CGSizeMake(84, 30));
    }];
    
    
    // 关联
    self.plusMinusView = plusMinusView;
    self.minusBtn = plusMinusView.minusBtn;
    
    // 传值
    plusMinusView.iconImage = self.img;
    

}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
